<template>
    <div>
        <!-- <div class="cloginLogo">
             <img src="../../assets/logo2.png"/>
         </div>-->
        <div class="clogin">
            
            </div>
        </div>
        <!-- <div class="bottomTips">
             <span style="width:300px">Copyright© 2017-2019 北京中油瑞飞 版权所有</span>
         </div>-->
    </div>
</template>
<script>
    import md5 from 'js-md5';
    import {Api} from '../../api/index.js'
    import {sessionStorage, cookie} from '../../common/cacheUtils.js';

    export default {
        mounted: function () {
            var search=window.location.href.split('?')[1];//截取URL？后面的参数
            var params={};
            if(search!=""){
            　　search.split("&").forEach(
                    function(val){
        　　　　        var arr=val.split("=");            
          　　　　      params[arr[0]]=arr[1];     
                    }
                )}
            var code=params.code
            var status = params.status
            if(code != null && code != 'undefine'){
                this.$http.get(Api.queryToken, {
                    params: {
                        code: code,
                    }
                }).then(res1 => {
                    sessionStorage('access_token').set("access_token", res1.data.access_token);
                    this.$http.get(Api.queryUserInfo, {
                        params: {
                            token: res1.data.access_token,
                        }
                    }).then(res => {
                        let data = JSON.stringify(res.data.data);
                        if (res.data.result == 'true') {
                            sessionStorage('token').set("Authorization", res.data.token);
                            sessionStorage('userId').set('userId', data);
                            const userInfo = {
                                createUserId: res.data.data.userId,
                                createUserName: res.data.data.userName,
                                createOrgId: res.data.data.orgInfo.orgId,
                                createOrgName: res.data.data.orgInfo.orgName
                            }
                            sessionStorage('paramUserInfo').set('userInfo', JSON.stringify(userInfo));
                            let redirect = decodeURIComponent('/');
                            this.$router.push({path: redirect})
                            this.$Message.info('登录成功');
                        } else {
                            this.$Message.error('账号/密码错误');
                        }
                    }).catch(e => {
                        console.error(e);
                        this.$Message.error('请求失败');
                    })
                })
            }
        },
        methods: {
            setCookie(c_name, c_pwd, exdays) {
                var exdate = new Date(); //获取时间
                exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); //保存的天数
                //字符串拼接cookie
                window.document.cookie = "userName" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();
                window.document.cookie = "userPwd" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();
            },
            //读取cookie
            getCookie: function() {
                if (document.cookie.length > 0) {
                    var arr = document.cookie.split('; '); //这里显示的格式需要切割一下自己可输出看下
                    for (var i = 0; i < arr.length; i++) {
                        var arr2 = arr[i].split('='); //再次切割
                        //判断查找相对应的值
                        if (arr2[0] == 'userName') {
                            this.formInline.user = arr2[1]; //保存到保存数据的地方
                        } else if (arr2[0] == 'userPwd') {
                            this.formInline.password = arr2[1];
                        }
                    }
                }
            },
            //清除cookie
            clearCookie: function(user) {
                this.setCookie(user, "", -1); //修改2值都为空，天数为负1天就好了
            }
        }
    }
</script>

<style scoped>
    @media screen and (min-width: 1400px) {
        .clogin {
            background-position: 0px 0px;
        }
    }

    .all {
        width: 680px;
        height: 320px;
        overflow: hidden;
        display: table;
        margin: auto
    }

    #left-model, #right-model {
        display: table-cell;
    }
    #left-model1, #right-model1 {
        display: table-cell;
    }

    .left-model {
        /*flex-direction: column;*/
        /*justify-content: center;*/
        /*align-items: center;*/
        width: 340px;
        height: 320px;
        background: #FFFFFF55;
        position: relative;
        /*margin: auto;*/
    }

    .clogin {
        display: flex;
        justify-content: flex-end;
        background-image: url(../../assets/img/login-bg1.jpg);
        background-repeat: no-repeat;
        background-size: cover;
        width: 100%;
        height: 100vh;
        min-height: 500px;
    }

    .fontName {
        width: 220px;
        height: 23px;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666465;
    }

    .cloginLogo {
        margin-left: 10vh;
        margin-top: 10vh;
    }

    .login_box {
        /*display: flex;*/
        /*flex-direction: column;*/
        /*justify-content: center;*/
        /*align-items: center;*/
        background: #FFFFFF;
        width: 340px;
        height: 320px;
        /*margin-top:91px;*/
        margin: auto;
        /*border-radius: 10px;*/
    }
    .login_box1 {
        /*display: flex;*/
        /*flex-direction: column;*/
        /*justify-content: center;*/
        /*align-items: center;*/
        background: #FFFFFF;
        width: 510px;
        height: 360px;
        /*margin-top:91px;*/
        margin: auto;
        /*border-radius: 10px;*/
    }
    .clogin_title {
        flex: auto;
        margin-top: 33px;
        width: 73px;
        height: 17px;
        font-size: 18px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666465;
    }

    .clogin_input {
        width: 260px;
        background: #F9F9F9;
        border: 0 solid #DBDBDB;
        border-radius: 4px;
    }

    .clogin_buttonInput {
        width: 260px;
        height: 34px;
        background: #E3393B;
        border-radius: 4px;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
    }

    /* element.style {
         width: 260px;
         margin: auto;
     }*/
    .clogin_remeberMe {
        width: 90px;
        height: 12px;
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #B3B3B3;
    }

    .clogin_code {
        width: 100px;
        height: 12px;
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #B3B3B3;
    }

    .clogin_code:hover{
        width: 100px;
        height: 12px;
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #e3393c;
    }

    .hse_logo {
        margin: 30px;
    }

    .loginselect {
        width: 120px;
        position: relative;
    }

    .bottomTips {
        margin-top: 18px;
        display: flex;
        justify-content: center;
        width: 100%;
        height: 14px;
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #757575;
    }

    .bottomTipsA {
        color: #9BADCB;
        padding: 0 15px 0 15px;
        font-family: Microsoft YaHei;
        font-weight: bold;
    }

    .swiper-container {
        width: 100%;
        height: 100%;
        margin-left: 8%;
        margin-top: auto;
        margin-right: auto;
    }

    .swiper1 {
        width: 450px;
        height: 450px;
    }

    .swiper2 {
        width: 600px;
        height: 600px;
    }
</style>
